import { Module } from '@nestjs/common';
import { AuthService } from './auth.service';
import { AuthController } from './auth.controller';
import { PassportModule } from '@nestjs/passport';
import { TypeOrmModule } from '@nestjs/typeorm';
import { User } from '../user/entities/user.entity';
import { JwtModule } from '@nestjs/jwt';
import { ConfigService } from '@nestjs/config';
import { LocalStrategy } from "./local.strategy"
import { UserModule } from '../user/user.module';
import { AuthGuard } from "./auth.guard"
import { JwtStrategy } from "./jwt.strategy"
import { MenuModule } from '../menu/menu.module';
import { APP_GUARD } from '@nestjs/core';
import { RolesGuard } from './roles.guard';
const jwtModule = JwtModule.registerAsync({
  global: true,//全局模块
  inject: [ConfigService],
  useFactory: async (configService: ConfigService) => {
    return {
      secret: configService.get('JWT_SECRET', 'test123456'),
      signOptions: { expiresIn: '4h' },//token 过期时间
    };
  },
});
@Module({
  imports: [
    PassportModule,
    TypeOrmModule.forFeature([User]),
    jwtModule,
    UserModule,
    MenuModule
  ],
  controllers: [AuthController],
  providers: [
    AuthService,
    LocalStrategy,
    // JwtStrategy,
    {
      provide: APP_GUARD,
      useClass: AuthGuard,
    },
    {
      provide: APP_GUARD,
      useClass: RolesGuard,
    },
  ],
  exports: [jwtModule]
})
export class AuthModule { }
